package sm.upgrade;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;

import sm.upgrade.api.UpgradePhase;
import sm.util.SMMap;

public class CurrencyUpgrade implements UpgradePhase {

	private static Logger logger = LoggerFactory.getLogger(UpgradePhase.class);

	private HibernateTemplate template;

	public void setTemplate(HibernateTemplate template) {
		this.template = template;
	}

	@Override
	public void upgrade() {
		logger.info("Updating currency records...");

		List<Object> currencies = (List<Object>) template.find("from currency");
		if (currencies != null) {
			for (Object currency : currencies) {
				SMMap currencyMap = (SMMap) currency;
				String currencyCode = (String) currencyMap.get("currency_code");
				if ("BSD".equals(currencyCode)) {
					currencyMap.put("name", "Bahamian Dollar");
				} else if ("KMF".equals(currencyCode)) {
					currencyMap.put("name", "Comorian Franc");
				} else if ("CYP".equals(currencyCode)) {
					currencyMap.put("name", "Cypriot Pound");
				} else if ("DEM".equals(currencyCode)) {
					currencyMap.put("name", "Deutsche Mark");
				} else if ("DOP".equals(currencyCode)) {
					currencyMap.put("name", "Dominican Republic Peso");
				} else if ("ECS".equals(currencyCode)) {
					currencyMap.put("name", "Ecuadorian Sucre");
				} else if ("SVC".equals(currencyCode)) {
					currencyMap.put("name", "El Salvadorian Colon");
				} else if ("FKP".equals(currencyCode)) {
					currencyMap.put("name", "Falkland Pound");
				} else if ("GHC".equals(currencyCode)) {
					currencyMap.put("name", "Ghanian Cedi");
				} else if ("XAU".equals(currencyCode)) {
					currencyMap.put("name", "Gold (ounces)");
				} else if ("ISK".equals(currencyCode)) {
					currencyMap.put("name", "Icelandic Krona");
				} else if ("LVL".equals(currencyCode)) {
					currencyMap.put("name", "Latvian Lat");
				} else if ("LSL".equals(currencyCode)) {
					currencyMap.put("name", "Lesotho Maloti");
				} else if ("MWK".equals(currencyCode)) {
					currencyMap.put("name", "Malawian Kwacha");
				} else if ("MVR".equals(currencyCode)) {
					currencyMap.put("name", "Maldives Rufiyaa");
				} else if ("NAD".equals(currencyCode)) {
					currencyMap.put("name", "Namibian Dollar");
				} else if ("ANG".equals(currencyCode)) {
					currencyMap.put("name", "Netherlands Antilles Guilder");
				} else if ("NIO".equals(currencyCode)) {
					currencyMap.put("name", "Nicaraguan Cordoba");
				} else if ("NOK".equals(currencyCode)) {
					currencyMap.put("name", "Norwegian Krone");
				} else if ("PKR".equals(currencyCode)) {
					currencyMap.put("name", "Pakistani Rupee");
				} else if ("XPD".equals(currencyCode)) {
					currencyMap.put("name", "Palladium (ounces)");
				} else if ("PEN".equals(currencyCode)) {
					currencyMap.put("name", "Peruvian New Sol");
				} else if ("XPT".equals(currencyCode)) {
					currencyMap.put("name", "Platinum (ounces)");
				} else if ("RUB".equals(currencyCode)) {
					currencyMap.put("name", "Russian Ruble");
				} else if ("STD".equals(currencyCode)) {
					currencyMap.put("name", "Sao Tome and Principe Dobra");
				} else if ("XAG".equals(currencyCode)) {
					currencyMap.put("name", "Silver (ounces)");
				} else if ("KRW".equals(currencyCode)) {
					currencyMap.put("name", "South Korean Won");
				} else if ("LKR".equals(currencyCode)) {
					currencyMap.put("name", "Sri Lankan Rupee");
				} else if ("SHP".equals(currencyCode)) {
					currencyMap.put("name", "St. Helena Pound");
				} else if ("TWD".equals(currencyCode)) {
					currencyMap.put("name", "Taiwanese Dollar");
				} else if ("TOP".equals(currencyCode)) {
					currencyMap.put("name", "Tonga Palanga");
				} else if ("TTD".equals(currencyCode)) {
					currencyMap.put("name", "Trinidad and Tobago Dollar");
				} else if ("UGS".equals(currencyCode)) {
					currencyMap.put("name", "Ugandian Shilling");
				} else if ("AED".equals(currencyCode)) {
					currencyMap.put("name", "United Arab Emirates Dirham");
				}
				template.update("currency", currencyMap);
			}
		}

		logger.info("  Finished updating currency records.");
	}
}
